"""
Logging_Model
"""
import logging, sys, time
from traceback import format_exc

# from os import path, mkdir

Time = lambda: time.strftime('%H:%M:%S')

Data = lambda: time.strftime('%Y-%m-%d')

# logging 初始化
logger = logging.getLogger("logger")  # 创建实例
formatter = logging.Formatter(
    "%(asctime)s \t%(process)d\t%(thread)d\t[%(filename)s-%(funcName)s]    \t%(levelname)s: %(message)s"
    )
#                          格式化：记录时间      进程-线程        -文件名-       函数名                 - 等级 -“message”
# 创建日志文件
file_handler = logging.FileHandler(f"./{Data()}.log")
file_handler.setFormatter(formatter)  # 日志文件的格式
# 终端日志
consle_handler = logging.StreamHandler(sys.stdout)
consle_handler.setFormatter(formatter)  # 日志文件的格式

logger.setLevel(logging.DEBUG)  # 设置日志文件等级

logger.addHandler(file_handler)  # 添加处理器
logger.addHandler(consle_handler)  #


def removeHandler():
    logger.removeHandler(file_handler)
    logger.removeHandler(consle_handler)


"""
def info(massage):
    logger.info(massage)
    logger.removeHandler(file_handler)


def error(massage):
    logger.error(massage)
    logger.removeHandler(file_handler)


def debug(massage):
    logger.debug(massage)
    logger.removeHandler(file_handler)


def critical(massage):
    logger.critical(massage)
    logger.removeHandler(file_handler)
"""


def Traceback():
    with open('./ErrorTraceback.log', mode='a', encoding='utf8') as ff:
        ff.write(f'**********{Data()}  {Time()}**********\n')
        ff.write(format_exc())
        ff.write('\n\n')


if __name__ == '__main__':
    logger.info('TEST')
